package com.system.service.UserService;

import com.system.dao.BaseDao;
import com.system.dao.UserDao.UserDao;
import com.system.dao.UserDao.UserDaoImpl;
import com.system.pojo.User;

import java.sql.Connection;
import java.sql.SQLException;

public class UserServiceImpl implements UserService{

    //声明DAO层的变量
  private final UserDao userDao;
    public UserServiceImpl() {
        userDao = new UserDaoImpl();
    }

    @Override
    public User Login(String UserCode, String UserPsw) throws SQLException {
        Connection connection = null;
        User user = null;

        connection = BaseDao.getConnection();
        user = userDao.Login(connection,UserCode,UserPsw);
        return user;
    }

    @Override
    public int Register(String UserCode, String UserPsw, int UserLossNub, int UserGetNub, String UserImgPath) throws SQLException {
        Connection connection = null;
        connection = BaseDao.getConnection();
        int ROWS = userDao.Register(connection,UserCode,UserPsw,UserLossNub,UserGetNub,UserImgPath);

        return ROWS;
    }

    @Override
    public boolean IfRepetition(String UserCode) throws SQLException {
        Connection connection =null;
        connection = BaseDao.getConnection();
        boolean flag = userDao.IfRepetition(connection,UserCode);
        return flag;
    }

    @Override
    public int UpdatePsw(String updatePsw, int UserId) throws SQLException {
        Connection connection = null;
        connection = BaseDao.getConnection();
        int ROWS = userDao.UpdatePsw(connection,updatePsw,UserId);
        return ROWS;
    }
}
